import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class CustomAppBar extends AppBar {
  CustomAppBar.leftTitle({
    super.key,
    String title = "",
    Color? titleColor,
    double? titleSize,
    double? toolbarHeight,
    FontWeight titleWeight = FontWeight.w400,
    Color backgroundColor = Colors.white,
    VoidCallback? callback,
  }) : super(
          leading: IconButton(
            alignment: Alignment.centerRight,
            icon: Icon(
              Icons.arrow_back_ios_new_outlined,
              color: Colors.black,
              size: 36.w,
            ),
            padding: EdgeInsets.only(top: 4.h),
            onPressed: () {
              if (callback != null) {
                callback.call();
                return;
              }
              Get.back();
            },
          ),
          leadingWidth: 80.w,
          toolbarHeight: toolbarHeight ?? 88.h,
          title: Text(
            title,
            style: TextStyle(
                color: titleColor ?? const Color(0xFF333333),
                fontSize: titleSize ?? 36.sp,
                fontWeight: titleWeight),
          ),
          titleSpacing: 8.w,
          backgroundColor: backgroundColor,
          elevation: 0,
        );

  CustomAppBar(
    String titleName, //页面标题，必须
    {
    super.key,
    bool isCenterTitle = true, //是否中间居中，默认中间居中，参数可选
    final actions, //右边部分，可能存放图标，文字等，可能还有点击事件，参数可选
    // final backIcon =
    //左边返回箭头图标，默认是<，可自定义，，参数可选也可以是文字
    final String rightText = '', //右边文字，参数可选
    final callBack,
    final rightCallback, //右边文字或者图标的点击函数，参数可选
    Color backgroundColor = Colors.white,
  }) : super(
          title: Text(
            titleName,
            style: TextStyle(
                color: const Color(0xFF333333),
                fontSize: 36.sp,
                fontWeight: FontWeight.normal),
          ),
          leading: TextButton(
              onPressed: () => callBack ?? Get.back(),
              child: Image(
                image: const AssetImage(
                    'assets/images/public_black_back_icon.png'),
                width: 48.h,
                height: 48.h,
                fit: BoxFit.contain,
              )),
          centerTitle: isCenterTitle,
          backgroundColor: backgroundColor,
          elevation: 0,
          toolbarHeight: 88.h,
          actions: actions ??
              <Widget>[
                Padding(
                  padding: const EdgeInsets.only(right: 10.0),
                  child: Center(
                    child: GestureDetector(
                      onTap: () {
                        rightCallback();
                      },
                      child: Text(rightText),
                    ),
                  ),
                ),
              ],
        );
}
